import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {VideoListService} from "../../service/http-service/getvideolist.service";
import {GetVideoDetailService} from "../../service/http-service/getVideoDetail.service";
import {ApplicantService} from "../../service/http-service/applicant.service";


/**
 * Generated class for the PurchaseHistoryPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-purchase-history',
  templateUrl: 'purchase-history.html',
})
export class PurchaseHistoryPage {

  sliders:{};
  currentPage: any;
  video_datas: any;
  lastPage: any;
  video1: any;
  video2: any;
  video={};



  constructor(public navCtrl: NavController, public navParams: NavParams,
              public videoListService: VideoListService, public getVideoDetailService: GetVideoDetailService,
              public applicantService: ApplicantService) {
  }


  ionViewWillEnter(){




    // this.dofresh();
    // this.getMyVipDetail();
    this.getNotpayDetail();
    this.getPayVideoDetail();


  }




  getPayVideoDetail() {
    this.videoListService.getPaidVideos().subscribe(resp => {
      if (resp.data !== null && resp.code == 200) {
        this.video1 = resp.data;


        // console.log(resp.data);
        // localStorage.setItem("video111", resp.data);
        // console.log(this.video.url)


      } else if (resp.data !== null && resp.code == 1401) {
        console.log("errrovideo");
        this.applicantService.freshTokenn();
      }
    }, error2 => {

      console.log(error2);
    });
  }


  getNotpayDetail() {
    this.videoListService.getNotpayOrder().subscribe(resp => {
      if (resp.data !== null && resp.code == 200) {
        this.video2 = resp.data;


        // console.log(resp.data);
        // localStorage.setItem("video111", resp.data);
        // console.log(this.video.url)


      } else if (resp.data !== null && resp.code == 1401) {
        console.log("errrovideo");
        this.applicantService.freshTokenn();
      }
    }, error2 => {

      console.log(error2);
    });
  }


  date1(time: any) {
    return new Date(time).toLocaleString().replace(/:\d{1,2}$/, ' ');
  }


  // dofresh(){
  //   this.currentPage=1;
  //
  //   this.videoListService.postVideoList(this.currentPage).subscribe(resp=>{
  //
  //     // console.log("aaaaaa")
  //     if (resp.data!==null){
  //
  //       // console.log(resp.data);
  //
  //
  //       this.video_datas=resp.data.list;
  //       this.lastPage=resp.data.isLastPage;
  //
  //       // this.sliders=resp.data;
  //       console.log(resp.data);
  //       // console.log(this.video_datas[0].img);
  //       // console.log(this.video_datas.list[4].img);
  //     }else {
  //       console.log("resp.data==null")
  //     }
  //   },error2 => {
  //     console.log("error");
  //     console.log(error2);
  //   });
  //
  // }

  new (videoId:number){

    this.navCtrl.push('ListvidoPage',{'Id':videoId});
  }

  new1 (videoId:number,orderNum:number){

    this.navCtrl.push('PayPage',{'Id':videoId,'orderNum':orderNum});
  }

}
